package com.atguigu01.create.exer1;



class EvenNumberPrint extends Thread {

    //打印偶数
    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            if(i % 2 == 0) {
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }
    }
}


class OddNumberPrint extends Thread {

    //打印奇数
    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            if(i % 2 != 0) {
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }
    }
}

public class PrintNumberTest {

    public static void main(String[] args) {


        //方式一：
//        EvenNumberPrint evenNumberPrint = new EvenNumberPrint();
//        OddNumberPrint oddNumberPrint = new OddNumberPrint();
//
//        evenNumberPrint.start();
//        oddNumberPrint.start();

        //方式二：匿名子类的匿名对象
/*        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i <= 100; i++) {
                    if(i % 2 != 0) {
                        System.out.println(Thread.currentThread().getName() + ":" + i);
                    }
                }
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i <= 100; i++) {
                    if(i % 2 == 0) {
                        System.out.println(Thread.currentThread().getName() + ":" + i);
                    }
                }
            }
        }.start();*/

        //方式三：匿名实现类的匿名对象
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i <= 100; i++) {
                    if(i % 2 == 0) {
                        System.out.println(Thread.currentThread().getName() + ":" + i);
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i <= 100; i++) {
                    if(i % 2 != 0) {
                        System.out.println(Thread.currentThread().getName() + ":" + i);
                    }
                }
            }
        }).start();
    }
}
